using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Data.Sql;
using DTO;

namespace DAO
{
    public class SuaDAO
    {

        public static DataTable LayThongTinSua()
        {
            DataTable dt = SqlDataAccessHelper.ExecuteQuery("spLayThongTinSua", null);
            return dt;
        }
        #region KiemTraNhapSua

        public static bool NhapSua(SuaDTO sua)
        {
            bool result = false;
            try
            {
                // Create List Sql Parameter
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MaHangHoa", sua.MaHangHoa));
                sqlParams.Add(new SqlParameter("@TenHangHoa", sua.TenHang));
                sqlParams.Add(new SqlParameter("@DonViTinh", sua.DonViTinh));
                // Call Store Procedure
                int n = SqlDataAccessHelper.ExecuteNoneQuery("spInsertSua", sqlParams);
                if (n == 1)
                    result = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }
        public static bool KiemTraNhapSua(String MaLoaiSua)
        {
            bool result = false;
            try
            {
                // Create List Sql Parameter
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MaHangHoa", MaLoaiSua));
                DataTable dt = SqlDataAccessHelper.ExecuteQuery("spKiemTraNhapSua", sqlParams);
                if (dt.Rows.Count >= 1)
                {
                    result = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }
        #endregion
    }
}
